package java44th.group.config.realm;

import com.google.gson.Gson;
import net.sf.json.JSON;
import net.sf.json.JSONString;
import org.apache.shiro.web.filter.authc.UserFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Aurhor: 徐云飞
 * @DATE: 2022/10/16 21:10
 * @Description:
 * @Version 1.0
 */
public class ShiroUserFilter extends UserFilter {


    @Override
    protected void redirectToLogin(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, IOException {
        // 返回json
        servletResponse.setContentType("application/json; charset=utf-8");

        Map<String, Object> response = new HashMap<String, Object>();
        response.put("errno", 501);
        response.put("errmsg", "请登录吧");

        Gson gson = new Gson();
        String json = gson.toJson(response);

        servletResponse.getWriter().write(json);
    }


}